package mushystuff.dtb.ws.to;

import java.util.Collection;
import java.util.Iterator;

import mushystuff.dtb.core.model.Product;

public class ProductTransferObject {
	
	private Product product;

	public ProductTransferObject (Product product) {
		if (product == null) {
			throw new IllegalArgumentException("Product can't be null");
		}
		this.product = product;
	}
	
	public long getId() {
		return product.getId();
	}
	
	public String getName() {
		return product.getName();
	}
	
	public boolean isActive() {
		return product.isActive();
	}
	
	public static ProductTransferObject[] toArray(Collection<Product> products) {
		ProductTransferObject[] res = new ProductTransferObject[products.size()];
		Iterator<Product> productsIterator = products.iterator();
		for(int i=0;i<products.size();i++) {
			res[i] = new ProductTransferObject(productsIterator.next());
		}
		return res;
	}
}
